const Express = require("express");
const ModelServer = require("../../servers/Model");
const ResponseHelper = require("../ResponseHelper");
const router = Express.Router();

/**
 * 获取所有报警信息
 */
router.get("/modelAll", async (req, res) => {
    try {
      const result = await ModelServer.getAllModel();
      ResponseHelper.sendData(result, res);
    } catch (err) {
      ResponseHelper.sendErr(err, res);
    }
  });
  
  /**
   * 添加一个报警信息
   */
  router.post("/addModel", async (req, res) => {
    try {
      const result = await ModelServer.addModel(req.body);
      ResponseHelper.sendData(result, res);
    } catch (err) {
      ResponseHelper.sendErr(err, res);
    }
  });
  /**
   * 更新报警信息
   */
  router.post("/updateModel/:id", async (req, res) => {
    const modelId = req.params.id;
    const modelObj = req.body;
    try {
      const result = await ModelServer.updateModel(modelId, modelObj);
      ResponseHelper.sendData(result, res);
    } catch (err) {
      ResponseHelper.sendErr(err, res);
    }
  });
  /**
   * 根据id删除用户
   */
  router.post("/delModel/:id", async (req, res) => {
    try {
      const modelId = req.params.id;
      const result = await ModelServer.deleteModel(modelId);
      ResponseHelper.sendData(result, res);
    } catch (err) {
      ResponseHelper.sendErr(err, res);
    }
  });
  
  module.exports = router;
  